﻿using System;
using System.Data;
using System.Windows.Forms;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using SRW;
using SRW.BLL;

public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //界面主要部分进行初始化
            DataList1.DataSource = SQL.GetDataTable("wtlink", "select * from wtlink");
            DataList1.DataBind();

            Repeater3.DataSource = SQL.GetDataTable("wtnews", "select top 13 * from wtnews where wtnewsType='体育新闻' order by wtnewsDate desc");
            Repeater3.DataBind();

            Repeater2.DataSource = SQL.GetDataTable("wtnews", "select top 15 * from wtnews where wtnewsType='体育公告' order by wtnewsDate desc");
            Repeater2.DataBind();

            Repeater1.DataSource = SQL.GetDataTable("wtnews", "select top 13 * from wtnews where wtnewsType='教学动态' order by wtnewsDate desc");
            Repeater1.DataBind();
        }
    }
    public Wtuser IsUser(string username, string password,string usertype)
    {
        StringBuilder sBuilder = new StringBuilder();
        sBuilder.Append("select * from wtuser where ");
        sBuilder.Append(SqlFormat.FormatWhere("wtusername", publicConn.Quote(username)));
        sBuilder.Append(SqlFormat.FormatWhere("wtpassword", publicConn.Quote(password)));
        sBuilder.Append(SqlFormat.FormatWhere("wtusertype", publicConn.Quote(usertype), true, true));
        return bWtuser.select(sBuilder.ToString());
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["username"] != null || Session["usertype"] != null)
        {
            Anthem.Manager.AddScriptForClientSideEval("alert('已经登录！')");
            return;
        }
        string tmp = "";
        if (Session["mvc"] != null)
        {
            tmp = Session["mvc"].ToString();

        }
        if (string.IsNullOrEmpty(TextBox1.Text) || string.IsNullOrEmpty(TextBox2.Text))
        {
            Anthem.Manager.AddScriptForClientSideEval("alert('未填写用户名或密码！')");
            return;
        }
        if (string.IsNullOrEmpty(TextBox3.Text))
        {
            Anthem.Manager.AddScriptForClientSideEval("alert('请输入验证码！')");
            return;
        }
        if (TextBox3.Text.Trim().ToLower() == tmp.ToLower())
        {
            if (string.IsNullOrEmpty(TextBox1.Text) || string.IsNullOrEmpty(TextBox2.Text))
            {
                Anthem.Manager.AddScriptForClientSideEval("alert('未填写用户名或密码！')");
                return;
            }
            Wtuser mUser = null;
            mUser = IsUser(TextBox1.Text.Trim(), TextBox2.Text.Trim(), RadioButtonList1.SelectedItem.Text);
            if (mUser.pkID > 0)
            {
                Anthem.Manager.AddScriptForClientSideEval("alert('登录成功！')");
                CookieOper.CleanSession("mvc");
                Session["username"] = mUser.wtusername;
                Session["usertype"] = mUser.wtusertype;
                Session["stuproType"] = mUser.wtprotype;
                Response.Redirect("stuks.aspx");
            }
            else
            {
                Anthem.Manager.AddScriptForClientSideEval("alert('用户名或密码错误，请确认！')");
            }
        }
        else
        {
            Anthem.Manager.AddScriptForClientSideEval("alert('验证码错误，请重新输入！')");
            TextBox3.Text = "";
        }
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        RadioButtonList1.SelectedIndex = 0;
        RadioButtonList1.UpdateAfterCallBack = true;
        TextBox1.UpdateAfterCallBack = true;
        TextBox2.UpdateAfterCallBack = true;
        TextBox3.UpdateAfterCallBack = true;
    }
    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        //体育公告
        string newType = CDataCrypt.EncryptDES("1", CDataCrypt.KeyValue);
        Response.Redirect("morenews.aspx?newType=" + newType + "");
    }
    protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
    {
        //教学动态
        string newType = CDataCrypt.EncryptDES("2", CDataCrypt.KeyValue);
        Response.Redirect("morenews.aspx?newType=" + newType + "");
    }
    protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
    {
        //体育新闻
        string newType = CDataCrypt.EncryptDES("3", CDataCrypt.KeyValue);
        Response.Redirect("morenews.aspx?newType=" + newType + "");
    }
}
